#include<iostream>
using namespace std;
const int N = 110;
int g[N][N];
int n;
int main()
{
	int t;
	cin >> n >> t;
	g[1][0] = 1;
	while (t--) {
		int a, b;
		cin >> a >> b;
		if (a == -1)a = 0;
		for (int i = 0; i <= n; i++) {
			if (g[b][i]) {
				g[a][i] = 1;
			}
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (g[i][0])cnt++;
	}
	cout << cnt << endl;
	for (int i = 1; i <= n; i++) {
		if (g[i][0]) {
			cout << i << " ";
		}
	}
	return 0;
}